using System.Collections;
using System.Collections.Generic;
using QFramework;
using QFramework.Example;
using UnityEngine;

public abstract class PowerUp : GameItemsObject
{
    //protected override Collider2D collider2D => throw new System.NotImplementedException();

    public bool FliyingToPlayer {  get;set; }
    private int FlyingToPlayerFrameCount = 0;

    protected abstract void Execute();



    void Update()
    {
        if (FliyingToPlayer)
        {
            if (FlyingToPlayerFrameCount == 0)
            {
                GetComponent<SpriteRenderer>().sortingOrder = 5;
            }
            FlyingToPlayerFrameCount++;

            if (Player.Instance)
            {
                var dir = Player.Instance.gameObject.DirectionFrom(this);
                var dic = dir.magnitude;

                if (FlyingToPlayerFrameCount <= 15)
                {
                    transform.Translate(dir.normalized * -2 * Time.deltaTime);
                }
                else
                {
                    transform.Translate(dir.normalized * 7.5f * Time.deltaTime);
                }


                if (dic < 0.1f)
                {
                    Execute();
                }
            }
        }

    }
}
